import ReactDOM from 'react-dom'
import { Spin } from 'antd'
import './styles.less'
import React from 'react'

let requestCount = 0
// 显示loading
export function showLoading() {
  if (requestCount === 0) {
    let dom = document.createElement('div')
    dom.setAttribute('id', 'loading')
    const container = document.getElementById('root') || document.body
    container.appendChild(dom)
    ReactDOM.render(<Loading />, dom)
  }
  requestCount++
}

// 隐藏loading
export function hideLoading() {
  requestCount--
  if (requestCount === 0) {
    const container = document.getElementById('root') || document.body
    container.removeChild(document.getElementById('loading') as any)
    if (container.classList) container.classList.remove('adm-overflow-hidden')
  }
}

export default function Loading() {
  return (
    <div className={'dn-loading-content'}>
      <Spin />
    </div>
  )
}
